package com.sbtr.controller.feature;

import com.sbtr.business.feature.dto.FeCanvasDto;
import com.sbtr.business.feature.entity.FeCanvas;
import com.sbtr.business.feature.service.FeCanvasService;
import com.sbtr.common.LoginConstants;
import com.sbtr.common.PageDto;
import com.sbtr.common.Response;
import com.sbtr.controller.common.CommonController;
import com.sbtr.exception.BDException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 特征画布字段列表 前端控制器
 *
 * @author dgl
 * @since 2023-03-17
 */
@RestController
@RequestMapping("/feCanvas")
@Api(tags = "特征画布字段列表")
public class FeCanvasController extends CommonController<FeCanvas, FeCanvasService> {

    @Autowired
    private FeCanvasService feCanvasService;

    @GetMapping("/pageList")
    @ApiOperation(httpMethod = "GET", value = "特征画布字段列表列表")
    public Response<PageDto<FeCanvas>> pageList(FeCanvasDto feCanvasDto,HttpServletRequest request) {
        String algorithmUserId = request.getHeader("algorithmUserId");
        feCanvasDto.setCreater(algorithmUserId);
        return Response.success(feCanvasService.pageList(feCanvasDto));
    }


    @PostMapping("/save")
    @ApiOperation(httpMethod = "POST", value = "特征画布字段列表保存")
    public Response<FeCanvas> save(@RequestBody FeCanvas feCanvas, HttpServletRequest request) {
        String algorithmUserId = request.getHeader("algorithmUserId");
        feCanvas.setCreater(algorithmUserId);
        feCanvas.setId(null);
        if (feCanvas.insert()) {
            return Response.success(feCanvas);
        } else throw new BDException("保存失败");
    }

}

